﻿using Cinchoo.Core;
using Cinchoo.Core.Shell;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace ChoXsd
{
    public partial class ApplicationHost : ChoApplicationHost, IChoWindowApp
    {
        private Lazy<MainWindow> _window = new Lazy<MainWindow>(() => new MainWindow());

        public ApplicationHost()
        {
        }

        protected override void OnStart(string[] args)
        {
            try
            {
                ChoAppCmdLineParams x = new ChoAppCmdLineParams();
            }
            catch (ChoCommandLineArgException ex)
            {
                if (ChoApplication.ApplicationMode == ChoApplicationMode.Console)
                {
                    Console.WriteLine(ex.Message);
                    return;
                }
            }

            ShowMessage("Application Started... (OnStart)");
            base.OnStart(args);
        }

        public string BalloonTipText
        {
            get { return "XSD GUI tool is still running..."; }
        }

        public System.Windows.Forms.ContextMenu GetContextMenu(System.Windows.Forms.ContextMenu contextMenu)
        {
            return null;
        }

        public object Application
        {
            get { return null; }
        }

        public object MainWindow
        {
            get { return _window.Value; }
        }

        public string TooltipText
        {
            get { return "XSD GUI tool"; }
        }

        public System.Drawing.Icon TrayIcon
        {
            get { return null; }
        }

        protected override void ApplyFrxParamsOverrides(ChoGlobalApplicationSettings globalApplicationSettings, ChoMetaDataFilePathSettings metaDataFilePathSettings)
        {
            globalApplicationSettings.TrayApplicationBehaviourSettings.TurnOn = true;
            globalApplicationSettings.TrayApplicationBehaviourSettings.TrayAppTurnOnMode = ChoTrayAppTurnOnMode.OnMinimize;
            globalApplicationSettings.TrayApplicationBehaviourSettings.HideTrayIconWhenMainWindowShown = true;

            base.ApplyFrxParamsOverrides(globalApplicationSettings, metaDataFilePathSettings);
        }
    }

    static class Program
    {
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
        {
            ChoApplication.Run(new ApplicationHost(), args);
        }
    }
}
